package com.study.study.rabbitmq;

import cn.hutool.core.thread.NamedThreadFactory;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.Executors;

/**
 * @author: zack
 * @date: 2020/1/19 0019 下午 9:53
 * @Description:
 */
public class ReceiveMsg {

    private static final String EXCHANGE_NAME = "logs";

    public static void main(String[] argv) throws Exception {

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.0.15");
        factory.setPort(5672);
        factory.setUsername("root");
        factory.setPassword("Zy200010!");
        factory.setSharedExecutor(Executors.newFixedThreadPool(4, new NamedThreadFactory("mq", false)));
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("Test", true, false, false, null);

        channel.basicQos(100);

        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

        channel.basicConsume("Test", true, "8902", (consumerTag, delivery) -> {
            String message = new String(delivery.getBody(), StandardCharsets.UTF_8);
            System.out.println(" [x] Received '" + message + "'");
        }, consumerTag -> {
        });

    }
}
